#include "org_phnq_babel_log_Logger.h"
#include "kit.h"

using namespace phnq::kit::log;

JNIEXPORT jint JNICALL Java_org_phnq_babel_log_Logger_initNative
  (JNIEnv *env, jobject _this, jstring _category)
{
	const char *category = env->GetStringUTFChars(_category, 0);
	
	string catStr(category);
	jint nativeRef = (jint)Logger::get(catStr);
	env->ReleaseStringUTFChars(_category, category);
	
	return nativeRef;
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_destroyNative
  (JNIEnv *env, jobject _this, jint _nativeRef)
{
	Logger *logger = (Logger*)_nativeRef;
	delete logger;
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_debug
  (JNIEnv *env, jobject _this, jint _nativeRef, jstring _msg)
{
	Logger *logger = (Logger*)_nativeRef;
	const char *msg = env->GetStringUTFChars(_msg, 0);
	logger->debug(msg);
	env->ReleaseStringUTFChars(_msg, msg);
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_info
  (JNIEnv *env, jobject _this, jint _nativeRef, jstring _msg)
{
	Logger *logger = (Logger*)_nativeRef;
	const char *msg = env->GetStringUTFChars(_msg, 0);
	logger->info(msg);
	env->ReleaseStringUTFChars(_msg, msg);
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_warning
  (JNIEnv *env, jobject _this, jint _nativeRef, jstring _msg)
{
	Logger *logger = (Logger*)_nativeRef;
	const char *msg = env->GetStringUTFChars(_msg, 0);
	logger->warning(msg);
	env->ReleaseStringUTFChars(_msg, msg);
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_error
  (JNIEnv *env, jobject _this, jint _nativeRef, jstring _msg)
{
	Logger *logger = (Logger*)_nativeRef;
	const char *msg = env->GetStringUTFChars(_msg, 0);
	logger->error(msg);
	env->ReleaseStringUTFChars(_msg, msg);
}

JNIEXPORT void JNICALL Java_org_phnq_babel_log_Logger_critical
  (JNIEnv *env, jobject _this, jint _nativeRef, jstring _msg)
{
	Logger *logger = (Logger*)_nativeRef;
	const char *msg = env->GetStringUTFChars(_msg, 0);
	logger->critical(msg);
	env->ReleaseStringUTFChars(_msg, msg);
}
